package group.hhsw.purchase.service.impl;

import group.hhsw.common.model.params.RateAndTerm;
import group.hhsw.common.model.vo.DetailOrder;
import group.hhsw.common.model.params.Check;
import group.hhsw.feign.clients.ProductClient;
import group.hhsw.purchase.service.PurchaseService;
import group.hhsw.purchase.utils.CalculateInterest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("5")
public class CalculateInterestService implements PurchaseService {

    @Autowired
    private ProductClient productClient;

    @Override
    public DetailOrder atomicService(Check check) {
        RateAndTerm rateAndTerm = productClient.getRateAndTerm(check.getProductId());
        Float interest = CalculateInterest.calculate(rateAndTerm.getAnnualProfitRate() / 100, check.getPrincipal(), rateAndTerm.getTerm());
        DetailOrder detailOrder = new DetailOrder();
        detailOrder.setInterest(interest);
        detailOrder.setPrincipal(check.getPrincipal());
        return detailOrder;
    }
}
